import { WeElement, define } from 'omi'

import './index.css'

define("select_picture", class extends WeElement{
  
  data={
    picurl:""
  }

  install(){
   this.data.none_num=0
    this.data.bg_none = 1
    this.update()
  }
  
  none=()=>{
    this.fire('choosetype', {
      date: this.data.none_num = 1
    })
    this.update()
  }
  // 相机拍照
  chooseImg=()=>{
    wx.chooseImage({
      sourceType: ['camera'],
      success:(res)=>{
        console.log(res)
        const tempFilePaths = res.tempFilePaths[0];
        this.data.picurl = tempFilePaths
        this.fire('choosetype',{
          picurl: tempFilePaths,
           date: this.data.none_num = 1
        })
      }
    })
    console.log(this.data.picurl)
    this.update()
  }
  // 选择图片
  chooseImage=()=>{
    wx.chooseImage({
      count: 1,
      sourceType: ['album', 'camera'],
      success: (res) => {
        console.log(res)
        const tempFilePaths = res.tempFilePaths[0];
        this.data.picurl = tempFilePaths
        this.fire('choosetype', {
          picurl: tempFilePaths,
          date: this.data.none_num = 1
        })
      }
    })
  }
  bg_none = () => {
    this.fire('choosetype', {
      date: this.data.none_num = 1
    })
    this.update()
  }
    render(){
    return(
      <view>
        <view class="three_but" onClick={this.bg_none}></view>
          <view class="bottom_box">
            <view class="album line_height" onClick={this.chooseImg}>
              <text>拍照</text>
            </view>
            <view class="camera line_height" onClick={this.chooseImage}>
              <text>从相册选择</text>
            </view>
            <view class="none line_height" onClick={this.none}>
              <text>取消</text>
            </view>
          </view>
      </view>
     )
     }
})